package com.example.demo.controller;

import com.example.demo.entity.evaluate;
import com.example.demo.mapper.EvaluateMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
@CrossOrigin
public class evaluateController {

    @Autowired
    EvaluateMapper evaluateMapper;

    @GetMapping("/selectevaluateByname/{name}")
    public List<evaluate> selectevaluateByname(@PathVariable("name") String name) {
        List<evaluate> list = evaluateMapper.selectevaluateByname(name);
        for (int i = 0; i < evaluateMapper.selectevaluateByname(name).size(); i++) {
            String str = list.get(i).getTime().replace(",", ":");
            list.get(i).setTime(str);
        }
        return list;
    }

    @GetMapping("/addeveluate/{user}/{name}/{score}/{evaluate}/{shijian}/{ordertime}")
    public String addeveluate(@PathVariable("user") String user, @PathVariable("name") String name,
                              @PathVariable("score") int score, @PathVariable("evaluate") String evaluate,
                              @PathVariable("shijian") String shijian, @PathVariable("ordertime") String ordertime) {
        evaluate e = new evaluate();
        e.setUser(user);
        e.setName(name);
        e.setScore(score);
        e.setEvaluate(evaluate);
        e.setTime(shijian);
        e.setOrdertime(ordertime);
        evaluateMapper.addevaluate(e);
        return "cg";
    }

}
